#!/bin/bash
yum -y install yum-utils
# yum install centos-release-openstack-pike -y
# 同样使用aliyun的镜像
echo "
[centos-openstack-pike]
name=centos openstack pike
baseurl=https://mirrors.aliyun.com/centos/7/cloud/x86_64/openstack-pike/
enabled=1
gpgcheck=0

[centos-ceph-jewel]
name=centos ceph jewel
baseurl=https://mirrors.aliyun.com/centos/7/storage/x86_64/ceph-jewel/
enabled=1
gpgcheck=0

[centos-qemu-ev]
name=centos qemu ev
baseurl=https://mirrors.aliyun.com/centos/7/virt/x86_64/kvm-common/
enabled=1
gpgcheck=0
">/etc/yum.repos.d/cloud.repo

echo "[mariadb-10.1]
name = MariaDB 10.1
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
enabled=1
gpgcheck=1

[mariadb-10.2]
name = MariaDB 10.2
baseurl = http://yum.mariadb.org/10.2/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
enabled=0
gpgcheck=1

[mariadb-10.3]
name = MariaDB 10.3
baseurl = http://yum.mariadb.org/10.3/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
enabled=0
gpgcheck=1
">/etc/yum.repos.d/MariaDB.repo

yum repolist

# 分别处理centos7，openstack相关，epel，mariadb

dest_dir=/var/www/yum/
targetid=centos7
mkdir -p $dest_dir/$targetid
#缓存安装包，超过20G，请确保磁盘有足够空间
reposync -d --download_path=$dest_dir/$targetid \
--repoid=base --repoid=extras --repoid=updates
#生成repodata目录并自动创建索引信息
createrepo -p -o $dest_dir/$targetid $dest_dir/$targetid

targetid=cloud
mkdir -p $dest_dir/$targetid
reposync -d --download_path=$dest_dir/$targetid \
--repoid=centos-ceph-jewel \
--repoid=centos-openstack-pike \
--repoid=centos-qemu-ev
createrepo -p -o $dest_dir/$targetid $dest_dir/$targetid

targetid=epel
mkdir -p $dest_dir/$targetid
reposync -d --download_path=$dest_dir/$targetid \
--repoid=epel
createrepo -p -o $dest_dir/$targetid $dest_dir/$targetid

targetid=mariadb
mkdir -p $dest_dir/$targetid
reposync -d --download_path=$dest_dir/$targetid \
--repoid=mariadb-10.1
createrepo -p -o $dest_dir/$targetid $dest_dir/$targetid

chown -R apache:apache $dest_dir
chmod -R +x $dest_dir

#httpd
echo "Alias /mirrors \"$dest_dir\"
<Directory \"$dest_dir\">
    Options Indexes FollowSymLinks
    AllowOverride None
    Order allow,deny
#    Deny from all
    Allow from all
    Require all granted
</Directory>
">/etc/httpd/conf.d/yum.conf

systemctl restart httpd
systemctl enable httpd